import axios from "axios";
import qs from 'qs'
import { message, notification } from "antd";
const instance = axios.create({
    baseURL:'http://shop.lingmeiyunhe.com/api/',
    timeout:10000
});

//请求拦截
instance.interceptors.request.use(
    (config) =>{
        return config
    },
    (error) =>{
        //请求错误时的处理
        return Promise.reject(error)
    }
);
//响应式拦截
instance.interceptors.response.use(
    (response)=>{
        if (response.data) {
            let { msg, status } = response.data;
            if (status === 400) {
              message.error(msg);
            }else if(status === 200){
                return response && response.data
            }
          }
        
    },
    (error)=>{
        return Promise.reject(error)
    }
)

const rewirteGet = instance.get;
instance.get = function (url, data, ...any) {
  let query = qs.stringify(data, { addQueryPrefix: true });
  return rewirteGet(url + query, ...any);
};

export default instance;